<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtdivwindow.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class veh_prefix extends Page
{
       public $Label1 = null;
       public $btnSet = null;
       public $editPrefix = null;
       public $lblPrefix = null;
       function veh_prefixJSUnload($sender, $params)
       {

       ?>
       if(document.getElementById('editPrefix').value=="")
       {
        window.opener.pop_it();
       }
       <?php

       }

       function veh_prefixCreate($sender, $params)
       {
        $query_prefix = "SELECT prefix FROM lookup_veh_count WHERE company_id='".$_SESSION['company_id']."'";
        $result_prefix = mysql_query($query_prefix) or die("SELECT PREFIX ".mysql_error());
        $row_prefix = mysql_fetch_array($result_prefix);

        $this->editPrefix->Text = $row_prefix['prefix'];

        if($row_prefix['prefix']!="")
        {
         echo "<script type='text/javascript'>
         window.opener.document.getElementById('hfSetPrefix').value = '1';
         window.opener.clearDiv();
         window.close();
         </script>";
        }
       }

       function btnSetClick($sender, $params)
       {
        $prefix = $this->editPrefix->Text;

        if($prefix=='')
        {
         echo "<script type='text/javascript'>
         alert('Please enter a prefix');
         </script>";
        }

        if($prefix!='')
        {
         $query_pre = "SELECT * FROM lookup_veh_count where company_id = '".$_SESSION['company_id']."'";
         $result_pre = mysql_query($query_pre);
         $num_rows = mysql_num_rows($result_pre);

         if($num_rows==0)
         {
         mysql_query("INSERT INTO lookup_veh_count (company_id,prefix,total_veh_count)
         VALUES ('".$_SESSION['company_id']."','".$prefix."','0')")
         or die("INSERT COUNT ".mysql_error());
         }

         if($num_rows!=0)
         {
         $query_set_prefix = "UPDATE lookup_veh_count SET prefix='".$this->editPrefix->Text."' WHERE
         company_id='".$_SESSION['company_id']."'";
         mysql_query($query_set_prefix) or die("SET PREFIX ".mysql_error());
         }

         echo "<script type='text/javascript'>
         window.opener.document.getElementById('hfSetPrefix').value = '1';
         window.opener.clearDiv();
         window.close();
         </script>";
        }
       }

}

global $application;

global $veh_prefix;

//Creates the form
$veh_prefix=new veh_prefix($application);

//Read from resource file
$veh_prefix->loadResource(__FILE__);

//Shows the form
$veh_prefix->show();

?>